package leecode.stringAndArray.DoubleArray;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MergeInterviews {
    public static void main(String[] args) {
        int[][] intervals = new int[][]{{1, 3}, {2, 6}, {8, 10}, {15, 18}};
        List<int[]> list = new ArrayList<>();
        Arrays.sort(intervals,(a,b)->a[0]-b[0]);

        for (int i = 0; i < intervals.length; i++) {
            int l = intervals[i][0];
            int r = intervals[i][1];
            if(list.size()==0 || l>list.get(list.size()-1)[1]){
                list.add(new int[]{l,r});
            }else{
                list.get(list.size()-1)[1] = Math.max(list.get(list.size()-1)[1],r);
            }
        }
        //return list.toArray(new int[list.size()-1][2]);

        }

    }



